package com.chenshu.demo.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-12-30
 * Time：23:48
 */

@Aspect//1、标识当前面为一个切面
@Component
public class LoginAop {
    //2、定义切点
    @Pointcut("execution(* com.chenshu.demo.controller.UserController.*(..))")
    public void pointcut() {
    }

    //3、通知
    @Before("pointcut()")
    public void before() {
        System.out.println("执行了前置通知");
    }

    @After("pointcut()")
    public void after() {
        System.out.println("执行了后置通知");
    }

    @Around("pointcut()")
    public Object doAround(ProceedingJoinPoint joinPoint) {
        Object obj = null;
        Long start = System.currentTimeMillis();
        try {
            obj = joinPoint.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        Long finish = System.currentTimeMillis();
        System.out.println("运行了：" + (finish-start) + "ms");
        return obj;
    }

}
